package net.meblabs.bookapp.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.ServiceLoader;

public class ServiceLoaderUtil {

	public static <T> Collection<T> load(Class<T> clazz) {
		ArrayList<T> services = new ArrayList<T>();
		ServiceLoader<T> loader = ServiceLoader.load(clazz);
		Iterator<T> iter = loader.iterator();
		while (iter.hasNext()) {
			services.add(iter.next());
		}
		return services;
	}
}
